<template>
    <el-input v-model="username" placeholder="用户名" />
    <el-input v-model="password" placeholder="密码" />
    <el-button type="primary" @click="login">登录</el-button>
</template>

<script setup>

import { ref } from 'vue'
import httpRequest from '@/request/index'
import router from '@/router/index'

const username = ref('')
const password = ref('')

function login() {
    httpRequest({
        url: '/auth/admin/login',
        method: 'post',
        data: {
            username: username.value,
            password: password.value
        }
    }).then((res) => {
        if (res.code === 0) {
            localStorage.setItem('token',res.data.token)
            res.data.token = null
            localStorage.setItem('uid', res.data.uid)
            localStorage.setItem('user', JSON.stringify(res.data))
            router.push({path: '/'})
        }
    })
}
</script>